CreateGdPictureImageFromByteArray(Byte[]) Method
Creates a new GdPicture image from an image file stored as an array of bytes. The newly created image is identified by its unique non-zero image identifier.
Please note that it is your responsibility to release the image resources once you have no use for them.
public int CreateGdPictureImageFromByteArray(
byte[]
)
public function CreateGdPictureImageFromByteArray(
: Bytearray of
): Integer;
public function CreateGdPictureImageFromByteArray(
: byte[]
) : int;
public: int CreateGdPictureImageFromByteArray(
byte[]*
)
public:
int CreateGdPictureImageFromByteArray(
array<byte>^
)
'Declaration
Public Overloads Function CreateGdPictureImageFromByteArray( _
ByVal () As Byte _
) As Integer
Parameters
- Data
- The image data stored in the array of bytes. This object must be initialized with the proper image data and it must be disposed of by the user as well.
Return Value
A unique image identifier of the GdPicture image representing the newly created image. The returned value is non-zero if the image is successfully created. Please first of all use the
GdPictureImaging.GetStat method to determine if this method has been successful.
Be aware that you need to release the image with the GdPictureImaging.ReleaseGdPictureImage method after being used.
Creating a GdPicture image from an image file stored as an array of bytes and saving to a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
using (Stream stream = File.Open("image.jpg", FileMode.Open))
{
// Load the file to an array of bytes for the sake of demonstration.
// In a production context, the image file should be obviously loaded with CreateGdPictureImageFromFile.
int size = (int)stream.Seek(0, SeekOrigin.End);
byte[] buffer = new byte[size];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(buffer, 0, size);
// Create the GdPicture image and save it as a PNG.
int imageID = gdpictureImaging.CreateGdPictureImageFromByteArray(buffer);
gdpictureImaging.SaveAsPNG(imageID, "image.png");
gdpictureImaging.ReleaseGdPictureImage(imageID);
}